package ch.usi.inf.pf2.editor;

import ch.usi.inf.pf2.Sheet;
import junit.framework.TestCase;


/**
 * @author mastrode
 */


public class TestUndoRedoStack extends TestCase {

	private UndoRedoStack urs;
	private Sheet sheet1;
	private Action action1;
		
		
	/**
	 * Set up properly some standard variable for the tests.
	 */
	protected void setUp()
	{
		urs = new UndoRedoStack();
		sheet1 = new Sheet();
		action1 = new Copy(sheet1, 3, 3);	
		((Copy)action1).evaluate();
	}
		
	
	/**
	 * Check if the undo() method returns a NullAction
	 * just in case the user has not done any action
	 * until that moment.
	 */
	public void testUndoOnEmptyStack()
	{
		assertEquals(new NullAction(), urs.undo());
	}
	
	
	/**
	 * Check if the undo() method returns the last
	 * action taken by the user.
	 */
	public void testUndoOnFullStack()
	{
		urs.addActionToUndoStack(action1);
		Action a = urs.getActionsForUndoCalling().peek();
		assertEquals(a, urs.getActionsForUndoCalling().pop());
	}
	
	
	
	/**
	 * Check if the redo() method returns a NullAction
	 * just in case the user has not redone any action
	 * until that moment.
	 */
	public void testRedoOnEmptyStack()
	{
		assertEquals(new NullAction(), urs.redo());
	}
	
	
	/**
	 * Check if the redo() method returns the last
	 * action redone by the user.
	 */
	public void testRedoOnFullStack()
	{
		urs.addActionToRedoStack(action1);
		assertEquals(action1, urs.redo());
	}
	
	
	/**
	 * Check if the getLastAction() method returns
	 * a NullAction if it's called on a just created
	 * UndoRedoStack, or the last action field otherwise.
	 */
	public void testGetLastAction()
	{
		assertEquals(new NullAction(), urs.getLastAction());
		urs.setLastAction(action1);
		assertEquals(action1, urs.getLastAction());
	}
	
	
	
}
	
